# -*- coding: utf-8 -*-
"""
Created on Thu Mar 13 10:45:35 2025

@author: usuario
"""
import numpy as np
import matplotlib.pyplot as plt
from AuxiliaryFunctions import plot_scope_signal_final
font = {'family' : 'DejaVu Sans',
        'weight' : 'normal',
        'size'   : '15'}
plt.rc('font', **font)
path = ".\\DataRectifierNb\\"
#%%
#%% Single IVs
import matplotlib.lines as mlines
filename = ['M04_NbAuEuSPt1_Ch2IV_I+I-_Bz=17Oe_1.6K.dat',
            'M25_NbAuEuSPt1_Ch2IV_I+I-_Bz=m17Oe_1.6K.dat']

#fig, ax1 = plt.subplots(figsize=(4.5, 3.5)) # 
fig, ax1 = plt.subplots(figsize=(4, 3.75))
for i, f in enumerate(filename):
    time, Is_A, Vs_V = np.loadtxt(path+f, skiprows=1, delimiter=',').T
    Is_mA, Vs_mV = Is_A * 1e3, Vs_V * 1e3
    filt_dV = np.abs(np.diff(Vs_mV,append=0))>50
    print((Is_mA[filt_dV]))
    if i == 0:
        plt.plot(Vs_mV[:500], Is_mA[:500], c='C{}'.format(i + 2)) # 
    else:
        plt.plot(Vs_mV[:600], Is_mA[:600], c='C{}'.format(i + 2)) #  + 2
plt.minorticks_on()
#plt.xlim([-400, 400])
#plt.ylim([-2.5, 2.5])
plt.tick_params(which='both', direction='in', top=True, right=True)
plt.xlabel('$V$ (mV)', fontsize=20)
plt.ylabel('$I$ (mA)', fontsize=20)
blue_line = mlines.Line2D([], [], color='C2', linestyle='-', linewidth=2, label='$B_z\\approx -$17 Oe')
orange_line = mlines.Line2D([], [], color='C3', linestyle='-', linewidth=2, label='$B_z\\approx +$17 Oe')
plt.legend(handles=[blue_line, orange_line])
plt.title('M04 and M25')
plt.savefig('IVsRectifierCh2.pdf')
plt.show()
#%%
#%% Time dependence vs R R=10 Ohm
filename = 'M23_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-10_Ohm_Vmax1.482V_Bz-17Oe__1p6K_FixedHolder_Vampl_5xfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=10\\, \\Omega$', xlim=[], ylim=[], dt = 0, tzero=True,
                  l_win=3, peak_sep=40, max_ref=10e-3, max_filt=20e-3) #0, 50
plt.savefig('M23_R_10_Ohm.pdf')
plt.show()
#%% Time dependence vs R R=20 Ohm
filename = 'M21_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-20_Ohm_Vmax1.672V_Bz-17Oe__1p6K_FixedHolder_Vampl_5xfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=20\\, \\Omega$', xlim=[], ylim=[],
                  dt = 0, tzero=True, l_win=1, peak_sep=80, max_ref=10e-3, max_filt=20e-3) #0, 50
plt.savefig('M21_R_20_Ohm.pdf')
plt.show()
#%% Time dependence vs R R=40 Ohm
filename = 'M20_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-40_Ohm_Vmax1.696V_Bz-17Oe__1p6K_FixedHolder_Vampl_5xfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=40\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=30e-3, max_filt=80e-3) #0, 50
plt.savefig('M20_R_40_Ohm.pdf')
plt.show()
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=40\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=30e-3) #0, 50
plt.show()
#%% Time dependence vs R R=60 Ohm
filename = 'M18_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-60_Ohm_Vmax1.804V_Bz-17Oe__1p6K_FixedHolder_Vampl_5xfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=60\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=50e-3, max_filt=70e-3) #0, 50
plt.savefig('M18_R_60_Ohm.pdf')
plt.show()
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=60\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=50e-3) #0, 50
plt.show()
#%% Time dependence vs R R=100 Ohm
filename = 'M08_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-100_Ohm_Vmax1.844V_Bz-17Oe__1p6K_FixedHolder_Vampl_5x_SimplCapCirNoCapfreq 37.35 Hz.dat'
#plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=100\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=70e-3, max_filt=100e-3) #0, 50
plt.savefig('M08_R_100_Ohm.pdf')
plt.show()
plot_scope_signal_final(path+filename, title='$R=100\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=50e-3) 
plt.show()
#%% Time dependence vs R R=200 Ohm
filename = 'M09_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-200_Ohm_Vmax1.844V_Bz-17Oe__1p6K_FixedHolder_Vampl_5x_SimplCapCirNoCapfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=200\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=70e-3, max_filt=120e-3) #0, 50
plt.savefig('M09_R_200_Ohm.pdf')
plt.show()
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=200\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=70e-3)
plt.show()
#%% Time dependence vs R R=300 Ohm
filename = 'M10_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-300_Ohm_Vmax1.844V_Bz-17Oe__1p6K_FixedHolder_Vampl_5xfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=300\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=80e-3, max_filt=120e-3) #0, 50
plt.savefig('M10_R_300_Ohm.pdf')
plt.show()
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=300\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=70e-3) 
plt.show()
#%% Time dependence vs R R=400 Ohm
filename = 'M11_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-400_Ohm_Vmax1.844V_Bz-17Oe__1p6K_FixedHolder_Vampl_5xfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=400\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=80e-3, max_filt=120e-3) #0, 50
plt.savefig('M11_R_400_Ohm.pdf')
plt.show()
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=400\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=70e-3)
plt.show()
#%% Time dependence vs R R=500 Ohm
filename = 'M16_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-500_Ohm_Vmax1.844V_Bz-17Oe__1p6K_FixedHolder_Vampl_5xfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=500\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=80e-3, max_filt=120e-3) #0, 50
plt.savefig('M16_R_500_Ohm.pdf')
plt.show()
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=500\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=70e-3) 
plt.show()
#%% Time dependence vs R R=600 Ohm
filename = 'M15_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-600_Ohm_Vmax1.844V_Bz-17Oe__1p6K_FixedHolder_Vampl_5xfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=600\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=80e-3, max_filt=120e-3) #0, 50

plt.savefig('M15_R_600_Ohm.pdf')
plt.show()

plot_scope_signal_final(path+filename, title='$R=600\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=80e-3) 
plt.show()
#%% Time dependence vs R R=700 Ohm
filename = 'M14_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-700_Ohm_Vmax1.844V_Bz-17Oe__1p6K_FixedHolder_Vampl_5xfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=700\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=90e-3, max_filt=120e-3) #0, 50
plt.savefig('M14_R_700_Ohm.pdf')
plt.show()
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=700\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=90e-3) #0, 50
plt.show()
#%% Time dependence vs R R=800 Ohm
filename = 'M13_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-800_Ohm_Vmax1.844V_Bz-17Oe__1p6K_FixedHolder_Vampl_5xfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=800\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=90e-3, max_filt=120e-3) #0, 50
plt.savefig('M13_R_800_Ohm.pdf')
plt.show()
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=800\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=90e-3) 
plt.show()
#%% Time dependence vs R R=900 Ohm
filename = 'M12_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-900_Ohm_Vmax1.844V_Bz-17Oe__1p6K_FixedHolder_Vampl_5xfreq 37.35 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=900\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=90e-3, max_filt=120e-3) #0, 50
plt.savefig('M12_R_900_Ohm.pdf')
plt.show()
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$R=900\\, \\Omega$', xlim=[], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=90e-3)
plt.show()

#%% 100 kHz results
filename = 'M47_NbAuEuSPt1_Ch2_I_V+V-_V_I+I-Open_Vmax2.41V_Bz-m17Oe__1p6K_FixedHolder_Vampl_5x_NoCap_freq_102000.0Hz.datfreq 102000.0 Hz.dat'
plt.figure(figsize=[3,2.5])
plot_scope_signal_final(path+filename, title='$f=100$ kHz', xlim=[0, 0.1], ylim=[], dt = 0,
                  tzero=True, l_win=1, peak_sep=40, max_ref=10e-3, max_filt=20e-3, plot_maxs=False) #0, 50
plt.savefig('M47_f_100kHz.pdf')
plt.show()
